package Schema::Result::ModelProperty;

use strict;
use warnings;
use utf8;

use Constants qw(AccessType_Private PropertyType_Persistent);

use base qw/DBIx::Class::Core/;

__PACKAGE__->table('ModelProperty');
__PACKAGE__->add_columns(
    Id => { data_type => 'integer', is_auto_increment => 1 },
    ModelId  => {},
    PropertyType  => {},
    AccessType  => {},
    Name  => {},
    Comment  => {},
    DataType  => {},
    DefaultValue  => {},
);
__PACKAGE__->set_primary_key('Id');

# 创建模型属性
sub Create{
    my ($class, $schema, $param) = @_;

    my $modelId = $param->{ModelId};
    my $propertyVo = $param->{PropertyVo};

    my $accessType = $propertyVo->GetAccessTypeEnum;
    my $dataType = $propertyVo->GetDataTypeEnum;
    my $createParam = {
        ModelId => $modelId,
        Name => $propertyVo->{Name},
        Comment => $propertyVo->{Comment},
        AccessType => $accessType,
        DefaultValue => $propertyVo->{DefaultValue},
        DataType => $dataType,
        PropertyType => PropertyType_Persistent,
    };

    my $newProperty = $schema->resultset('ModelProperty')->create($createParam);

    $newProperty->update;

    return $newProperty;
}

# 删除
sub Delete {
    my ($self) = @_;

    $self->delete;
}

1;
